package com.tomehay.termprojectmanage_server.service.impl;

import com.tomehay.termprojectmanage_server.mapper.PlanMapper;
import com.tomehay.termprojectmanage_server.pojo.Model.Plan;
import com.tomehay.termprojectmanage_server.service.PlanService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * (Plan表)服务实现类
 *
 * @author makejava
 * @since 2023-06-24 20:04:24
 */
@Service("planService")
public class PlanServiceImpl implements PlanService {
    @Resource
    private PlanMapper planMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Plan selectById(Integer id) {
        return this.planMapper.selectById(id);
    }

    /**
     * 分页查询
     *
     * @param start 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Plan> selectPage(int start, int limit) {
//        return this.planMapper.selectPage(start, limit);
        return null;
    }

    /**
     * 查询所有
     *
     * @return 实例对象的集合
     */
     @Override
     public List<Plan> selectAll() {
        return this.planMapper.queryAll();
     }
     
    /**
     * 根据条件查询
     *
     * @return 实例对象的集合
     */
    @Override
    public List<Plan> selectList(Plan plan) {
//        return this.planMapper.selectList(plan);
        return null;
    }
    
    /**
     * 新增数据
     *
     * @param plan 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(Plan plan) {
        plan.setCreateTime(LocalDateTime.now());
        return this.planMapper.insert(plan);
    }

    /**
     * 批量新增
     *
     * @param plans 实例对象的集合
     * @return 生效的条数
     */
    @Override
    public int batchInsert(List<Plan> plans) {
        return this.planMapper.insertBatch(plans);
    }

    /**
     * 修改数据
     *
     * @param plan 实例对象
     * @return 实例对象
     */
    @Override
    public Plan update(Plan plan) {
        this.planMapper.updateSelective(plan);
        return this.selectById(plan.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public int deleteById(Integer id) {
        return this.planMapper.deleteById(id);
    }
    
    /**
     * 查询总数据数
     *
     * @return 数据总数
     */
     @Override
     public int count(){
        return this.planMapper.count();
     }

    @Override
    public void divide(List<Plan> list) {
        planMapper.insertBatch(list);
    }

    @Override
    public List<Plan> selectAllByPid(Integer pid) {
        return planMapper.selectAllByPersonalTaskId(pid);
    }

    @Override
    public void changeStatus(Integer id) {
        Plan plan = planMapper.selectOneById(id);
        if (plan.getTaskstatus() == 1) {
            plan.setTaskstatus(0);
        } else {
            plan.setTaskstatus(1);
        }
        planMapper.updateSelective(plan);
    }
}

